<template>
  <a-form :rules="testRules" :model="testFormConfig.form" @finish="submit" :label-col="{ span: 6 }"
    :wrapper-col="{ offset: 1 }" label-align="right" ref="testFormRef" :disabled="hasPerm('ax:test:edit')">
    <FormCard title="编辑/新增" :back="back" subtitle="测试">
      <template #extra>
        <a-button htmlType="submit" type="primary" :loading="testTable.loading" block>
          保存
        </a-button>
      </template>
      <a-row :gutter="8">
        <a-col :span="16">
          <a-card>
            <a-form-item label="测试ID" name="testId">
              <a-input allow-clear placeholder="请输入测试ID" v-model:value="testFormConfig.form.testId">
              </a-input>
            </a-form-item>
            <a-form-item label="地区选择" name="district">
              <a-input allow-clear placeholder="请输入地区选择" v-model:value="testFormConfig.form.district">
              </a-input>
            </a-form-item>
            <a-form-item label="图片选择" name="imageField">
              <a-input allow-clear placeholder="请输入图片选择" v-model:value="testFormConfig.form.imageField">
              </a-input>
            </a-form-item>
            <a-form-item label="Markdown文件" name="mdField">
              <FormDate v-model="testFormConfig.form.mdField">
              </FormDate>
            </a-form-item>
            <a-form-item label="卡片封面" name="cardCover">
              <a-input allow-clear placeholder="请输入卡片封面" v-model:value="testFormConfig.form.cardCover">
              </a-input>
            </a-form-item>
            <a-form-item label="备注信息" name="remark">
              <a-input allow-clear placeholder="请输入备注信息" v-model:value="testFormConfig.form.remark">
              </a-input>
            </a-form-item>
            <a-form-item label="三向绑定" name="model">
              <a-input allow-clear placeholder="请输入三向绑定" v-model:value="testFormConfig.form.model">
              </a-input>
            </a-form-item>
            <a-form-item label="create_time" name="createTime">
              <FormDate v-model="testFormConfig.form.createTime">
              </FormDate>
            </a-form-item>
            <a-form-item label="update_time" name="updateTime">
              <FormDate v-model="testFormConfig.form.updateTime">
              </FormDate>
            </a-form-item>
          </a-card>
        </a-col>
        <AxExtra></AxExtra>
      </a-row>
    </FormCard>
  </a-form>
</template>

<script setup lang="ts">
import {
} from '../data/options';
import { hasPerm } from '@/utils/common/perm';
import type { Response } from '@/api/config/types';
import {
  createTest,
  updateTest,
} from '@/api/modules/ax/test/test';
import { notify, } from '@/utils/table/table';
import { testList } from '../data/curd';
import {
  testFormConfig,
  testRules,
  testFormRef
} from '../data/form';
import { testTable } from '../data/table';
import AxExtra from './AxExtra.vue';

const submit = async () => {
  testTable.value.loading = true;
  let result: undefined | Response<any> = undefined
  if (testFormConfig.value.form.testId) {
    const { data } = await updateTest(testFormConfig.value.form)
    result = data
  } else {
    const { data } = await createTest(testFormConfig.value.form)
    result = data
  }
  notify(result)
  testTable.value.loading = false;
  await testList();
  back();

};

const back = () => {
  testFormConfig.value.display = false;
  testFormConfig.value.reset!();
};

</script>

<style lang="scss" scoped></style>
